﻿using Newtonsoft.Json;
namespace Odyssey.Http.Implementations
{
    public class JsonHttpSerializer : IHttpSerializer
    {
        private JsonSerializerSettings _jsonSerializerSettings;
        public JsonHttpSerializer(IHttpConfiguration httpConfiguration)
        {
            _jsonSerializerSettings = httpConfiguration.JsonSerializerSettingsBuilder?.Invoke();
        }

        public T Deserialize<T>(string json)
        {
            return JsonConvert.DeserializeObject<T>(json);
        }

        public string Serialize(object obj)
        {
            return JsonConvert.SerializeObject(obj, _jsonSerializerSettings);
        }
    }
}
